<template>
  <div></div>
</template>
<script>
import { setStore, getStore, removeStore } from '@/utils/storage'
import axios from 'axios'
import { baseApi, baseUrl, wechatAuthUrlTail, preLoginUrl } from '@/config'
export default {
  data() {},
  computed: {},
  mounted() {
    let jumpUrl = getStore('loginRequestUrl')
    const code = this.GetQueryString('code')
          console.log(code)
    if (code !== '' && code != null && code !== undefined && code !== 'undefined') {
      axios({
        method: 'post',
        url: baseApi + 'app/auth/loginByMp',
        data: {
          code: code,
          scope:'1',
          activityCode:getStore('activityCode'),
          appid:getStore('appid')
        }
      })
        .then(res => {
          console.log('1',res.data.code,res.data.token)
          if (res.data.code === 0) {
            setStore('token', res.data.token)
            location.href = jumpUrl

          } else {
            location.href = jumpUrl
          }
        })
        .catch(res => {
          console.log('2')
          location.href = jumpUrl
        })
    }
  },
  methods: {
    GetQueryString(name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
      var r = window.location.search.substr(1).match(reg)
      if (r != null) return unescape(r[2])
      return null
    }
  }
}
</script>

<style scoped></style>
